<template lang="html">
  <div class="board panels">
    <div class="panel hotsongs on">
      <ul class="list">
        <router-link tag="li" 
        class="song url" 
        v-for="(item,index) in this.songInfo"
        :key="index"
        :to="{name:'MusicPlay',params:{songId: item.id}}"   
         >
          <div class="poster"><img :src="item.al.picUrl"></div>
          <div class="info">
            <div class="name">{{ item.name}}</div>
            <div class="author"><span
              class="author"
              v-for="(item,index) in item.ar"
              :key="index"
              style="margin-right:2px"
              >{{item.name}}</span>
          </div>
          </div>
        </router-link>
      </ul>
      <div class="more-songs url">
          查看该榜单&gt;
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      songInfo: [
        {
        id: 0,
        al: {
          picUrl: "" // 专辑图片
        },
        ar: [], // 歌手列表
        name: "" // 歌名
      }
      ]
    };
  },
  props: {
    parm: {
      type: String,
      default: ""
    }
  },
  mounted() {
    const url = this.HOST + "/toplist/detail";
    this.$axios
      .get(url)
      .then(res => {
        if (res) {
          var topList = res.data.list[this.parm];
          // 获取歌单歌曲
          const songUrl =
            this.HOST +
            `/playlist/track/all?limit=10&offset=0&id=${topList.id}`;
          this.$axios.get(songUrl).then(res => {
            if (res) {
              this.songInfo = res.data.songs;
            }
          });
        }
      })
      .catch(err => console.log('榜单歌曲报错', err.response.data.message));
  }
};
</script>

<style scoped>
.board {
  margin-bottom: 10px;
}

.panel {
  border-top: 1px solid #eee;
  position: relative;
  top: -1px;
  display: block;
  background: #fff;
}

.list {
  padding: 20px;
  padding-top: 0;
}

.panel .list li {
  height: 60px;
  border-bottom: 1px solid #eee;
  padding-left: 0;
  display: flex;
  padding-top: 10px;
}

.panel .list li .poster {
  position: relative;
  width: 45px;
  margin-right: 8px;
}

.panel .list li .poster img {
  border: 1px solid #eee;
}
.info {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  color: #333;
}

.info .author {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}

.more-songs {
  color: #999;
  margin-top: 9px;
  font-size: 12px;
  text-align: center;
  height: 32px;
  line-height: 32px;
}
</style>
